const { SingleList } = require("./SingleList");
var myList = new SingleList();
var arr = ["A", "B", "C", "D", "E", "F", "G"];

arr.forEach((item) => myList.append(item));

var C = myList.find("C");
var G = myList.findLast();
G.next = C;
function isLoop(list) {
  // 使用快慢指针
  var p = list.head;
  var q = list.head;

  while (q) {
    p = p.next;
    if (p.next) {
      q = q.next.next;
    }
    if (p === q) {
      console.log("this list has rings");
      return;
    }
  }
  console.log("this list has no rings");
}

isLoop(myList);
